// 后台API接口
const API_URL = 'http://localhost:8080/admin';
import adminRequest from '@/Intercepter/adminRequest';
import axios from 'axios';

// 发送请求
export function apiGetRooms() {
  return axios.get(`${API_URL}/rooms`);
}

// 管理员登录
export function apiAdminLogin(data: { username: string; password: string }) {
  return axios.post(`${API_URL}/login`, data);
}

// 获取当前酒店信息
export function apiGetHotelInfo() {
  return adminRequest.get(`${API_URL}/hotelInfo`);
}

// 创建酒店
export function apiCreateHotel(data: { name: string; address: string; phone: string; desc: string; logo?: string; photos?: string }) {
  return adminRequest.post(`${API_URL}/create-hotel`, data);
}

// 上传酒店图片
export function apiUploadHotelImage(formData: FormData) {
  return axios.post(`http://localhost:8080/user/upload-avatar`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 更新酒店信息
export function apiUpdateHotel(data: { name: string; address: string; phone: string; city: string; desc: string; logo?: string; photos?: string }) {
  return adminRequest.post(`${API_URL}/update-hotel`, data);
}

// 客房管理API
// 获取客房列表
export function apiGetRoomsList(hotelId: string | number, page = 1, pageSize = 10) {
  return adminRequest.get(`http://localhost:8080/rooms/list`, {
    params: { hotelId, page, pageSize }
  });
}

// 获取客房详情
export function apiGetRoomDetail(id: string | number) {
  return adminRequest.get(`http://localhost:8080/rooms/${id}`);
}

// 添加客房
export function apiAddRoom(roomData: any) {
  return adminRequest.post(`http://localhost:8080/rooms/add`, roomData);
}

// 更新客房
export function apiUpdateRoom(roomData: any) {
  return adminRequest.put(`http://localhost:8080/rooms/update`, roomData);
}

// 删除客房
export function apiDeleteRoom(id: number) {
  return adminRequest.delete(`http://localhost:8080/rooms/delete/${id}`);
}

// 上传客房图片
export function apiUploadRoomImage(formData: FormData) {
  return adminRequest.post(`http://localhost:8080/rooms/upload-image`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 酒店位置管理API
// 获取酒店位置信息
export function apiGetHotelLocation(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/hotel/${hotelId}/location`);
}

// 创建酒店位置信息
export function apiCreateHotelLocation(hotelId: string, locationData: any) {
  return adminRequest.post(`http://localhost:8080/hotel/${hotelId}/location`, locationData);
}

// 更新酒店位置信息
export function apiUpdateHotelLocation(hotelId: string, locationData: any) {
  return adminRequest.put(`http://localhost:8080/hotel/${hotelId}/location`, locationData);
}

// 酒店政策管理API
// 获取酒店政策信息
export function apiGetHotelPolicy(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/hotel/${hotelId}/policy`);
}

// 创建酒店政策信息
export function apiCreateHotelPolicy(hotelId: string, policyData: any) {
  return adminRequest.post(`http://localhost:8080/hotel/${hotelId}/policy`, policyData);
}

// 更新酒店政策信息
export function apiUpdateHotelPolicy(hotelId: string, policyData: any) {
  return adminRequest.put(`http://localhost:8080/hotel/${hotelId}/policy`, policyData);
}

// 酒店设施管理API
// 获取酒店设施信息
export function apiGetHotelAmenities(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/hotel/${hotelId}/amenities`);
}

// 创建酒店设施信息
export function apiCreateHotelAmenities(hotelId: string, amenitiesData: any) {
  return adminRequest.post(`http://localhost:8080/hotel/${hotelId}/amenities`, amenitiesData);
}

// 更新酒店设施信息
export function apiUpdateHotelAmenities(hotelId: string, amenitiesData: any) {
  return adminRequest.put(`http://localhost:8080/hotel/${hotelId}/amenities`, amenitiesData);
}

// ========== 评论管理API ==========

// 获取酒店评论列表（带筛选条件）
export function apiGetHotelReviews(hotelId: string, params: {
  rating?: number;
  status?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  pageSize?: number;
}) {
  return adminRequest.get(`http://localhost:8080/review/admin/hotel-reviews`, {
    params: { hotelId, ...params }
  });
}

// 获取酒店评论统计信息
export function apiGetHotelReviewStats(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/review/hotel-stats`, {
    params: { hotelId }
  });
}

// 回复评论
export function apiReplyReview(reviewId: string, reply: string) {
  return adminRequest.post(`http://localhost:8080/review/admin/reply`, null, {
    params: { reviewId, reply }
  });
}

// 更新评论状态（隐藏/显示）
export function apiUpdateReviewStatus(reviewId: string, status: string) {
  return adminRequest.post(`http://localhost:8080/review/admin/update-status`, null, {
    params: { reviewId, status }
  });
}

// ========== 订单管理API ==========

// 获取酒店订单列表
export function apiGetHotelBookings(hotelId: string, page = 1, pageSize = 10) {
  return adminRequest.get(`http://localhost:8080/booking/hotel/${hotelId}`, {
    params: { page, pageSize }
  });
}

// 搜索酒店订单
export function apiSearchHotelBookings(hotelId: string, params: {
  keyword?: string;
  status?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  pageSize?: number;
}) {
  console.log('API调用参数:', params); // 添加调试日志
  return adminRequest.get(`http://localhost:8080/booking/hotel/${hotelId}/search`, {
    params
  });
}

// 获取订单详情(管理员视角)
export function apiGetBookingDetailForAdmin(bookingId: string) {
  return adminRequest.get(`http://localhost:8080/booking/hotel/detail/${bookingId}`);
}

// 更新订单状态
export function apiUpdateBookingStatus(bookingId: string, status: string) {
  return adminRequest.post(`http://localhost:8080/booking/hotel/update-status`, null, {
    params: { bookingId, status }
  });
}

// 更新订单支付状态
export function apiUpdateBookingPayStatus(bookingId: string, payStatus: number) {
  return adminRequest.post(`http://localhost:8080/booking/hotel/update-pay-status`, null, {
    params: { bookingId, payStatus }
  });
}

// 获取订单统计数据
export function apiGetBookingStats(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/booking/hotel/${hotelId}/stats`);
}

// 获取订单图表统计数据
export function apiGetOrderStatistics(hotelId: string, params?: {
  period?: string; // month, quarter, year
  startDate?: string;
  endDate?: string;
}) {
  return adminRequest.get(`http://localhost:8080/booking/hotel/${hotelId}/chart-stats`, {
    params
  });
}

// 获取房型订单分布统计
export function apiGetRoomTypeBookingStats(hotelId: string) {
  return adminRequest.get(`http://localhost:8080/booking/hotel/${hotelId}/room-type-stats`);
}









